package cn.wizzer.app.crown.modules.models;

import cn.wizzer.framework.base.model.BaseModel;
import lombok.Data;
import org.nutz.dao.entity.annotation.*;
import org.nutz.dao.interceptor.annotation.PrevInsert;

import java.io.Serializable;
import java.util.Objects;

/**
 * 爬取网址及账号密码配置
 * 初始化就项目就加载到redis
 * 永不过期，删除修改再处理
 *
 * @author
 */
@Data
@Table("crown_config")
public class CrownConfig extends BaseModel implements Serializable {

    private static final long serialVersionUID = 1L;

    @Column
    @Name
    @Comment("ID")
    @ColDefine(type = ColType.VARCHAR, width = 32)
    @PrevInsert(els = {@EL("uuid()")})
    private String id;
    /**
     * url
     */
    @Column
    @Comment("站点")
    @ColDefine(type = ColType.VARCHAR, width = 64)
    private String site;

    @Column
    @Comment("账号")
    @ColDefine(type = ColType.VARCHAR, width = 64)
    private String username;

    @Column
    @Comment("密码")
    @ColDefine(type = ColType.VARCHAR, width = 64)
    private String passwords;

    /**
     * roll:滚盘 static：早盘、今日、赛果
     */
    @Column("use_type")
    @Comment("用途")
    @ColDefine(type = ColType.VARCHAR, width = 32)
    private String useType;


    @Column("remark")
    @Comment("备注")
    @ColDefine(type = ColType.VARCHAR, width = 128)
    private String remark;

    @Column
    @Comment("状态>运行中 busy,空闲 free")
    @ColDefine(type = ColType.VARCHAR, width = 8)
    private String state;

    @Column
    @Comment("是否禁用0否1是")
    @ColDefine(type = ColType.BOOLEAN)
    private boolean disabled;

    private boolean locked = false;

    /**
     * 用户ID
     */
    private String uid;

    /**
     * cookie
     */
    private String cookie;

    /**
     * 实际请求的地址
     */
    private String realSite;


    /**
     * 是否被登出
     */
    private boolean logout = false;

    /**
     * 任务type,为了跟踪记录
     */
    private String type;

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        CrownConfig that = (CrownConfig) o;
        return Objects.equals(username, that.username);
    }

    @Override
    public int hashCode() {
        return Objects.hash(username);
    }

}
